package cn.lasse.springframework.bean;

import cn.lasse.springframework.beans.BeansException;
import cn.lasse.springframework.beans.factory.*;
import cn.lasse.springframework.context.ApplicationContext;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class UserService implements BeanNameAware, BeanClassLoaderAware, ApplicationContextAware, BeanFactoryAware, InitializingBean, DisposableBean {
    private ApplicationContext applicationContext;
    private BeanFactory beanFactory;
    private String uid;
    private String company;
    private String location;
    private IUserDao iUserDao;

    public String queryUserInfo() {
        return iUserDao.queryUserName(uid);
    }

    public String selectAll(String uid) {
        return iUserDao.selectAll(uid);
    }
    public void initDataMethod() {
        System.out.println("UserService 执行：init-method");
    }

    /**
     * Bean 处理了属性填充后调用
     *
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("UserService 执行：UserService.afterPropertiesSet");
    }

    /**
     * 销毁方法
     *
     * @throws Exception
     */
    @Override
    public void destroy() throws Exception {
        System.out.println("UserService 执行：UserService.destroy");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("ClassLoader：" + classLoader);
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("Bean Name is：" + name);
    }
}
